var current_page = 2;
var ajax_lock = 0;
function get_more_events() {
	if (ajax_lock == 0) {
		ajax_lock = 1;
		$("#see-more").html(
				'<img src="' + global.context
						+ '/img/loading_16x16.gif" />载入中...');
		ajax_get_more_events()
	}
}
function ajax_get_more_events() {
	$
			.getJSON(
					global.context + "/event/ajax_get_more_events",
					{
						page : current_page
					},
					function(a) {
						if (a.code >= 0) {
							$
									.each(
											a.events,
											function(f, b) {
												var c = b.start_at.substr(0, 4);
												if (current_year != c) {
													current_year = c;
													var e = document
															.createElement("li");
													e.className = "year-mark";
													e.innerHTML = current_year
															+ "年";
													$("#event-list-ul").append(
															e)
												}
												var m = document
														.createElement("li");
												m.className = "event-item";
												var k = document
														.createElement("div");
												k.className = "event-time-label";
												var d = document
														.createElement("div");
												d.className = "event-item-content";
												var g = document
														.createElement("div");
												g.calss = "event-item-head";
												var j = document
														.createElement("div");
												j.className = "event-video-image";
												var l = document
														.createElement("div");
												l.className = "event-detail";
												var o;
												var h;
												var n = "";
												o = document
														.createElement("div");
												o.className = "event-video-city";
												o.innerHTML = "<p>"
														+ b.start_at + "·"
														+ b.city + "</p>";
												g.appendChild(o);
												o = document
														.createElement("div");
												o.className = "event-detail-title";
												o.innerHTML = '<h2><a href="'
														+ global.context
														+ "/event/" + b.id
														+ '">' + b.name
														+ "</a></h2>";
												g.appendChild(o);
												h = document.createElement("a");
												h.href = global.context
														+ "/event/" + b.id
														+ "#res-download";
												h.className = "play-icon";
												j.appendChild(h);
												h = document.createElement("a");
												h.href = global.context
														+ "/event/" + b.id
														+ "#res-download";
												if (b.cover_image == null) {
													n = '<img src="'
															+ global.context
															+ '/img/data/events/cover_default.jpg" alt="'
															+ b.name
															+ '" title="'
															+ b.name
															+ '" width="200" />'
												} else {
													n = '<img src="'
															+ global.context
															+ b.cover_image
															+ '" alt="'
															+ b.name
															+ '" title="'
															+ b.name
															+ '" width="200" />'
												}
												if (b.series_num != null
														&& b.series_num != 0) {
													n += '<label class="series-num">第'
															+ b.series_num
															+ "期</label>"
												}
												h.innerHTML = n;
												j.appendChild(h);
												n = "";
												if (b.speakers != undefined) {
													n = '<p class="title"><span class="light-grey">主讲人</span>&nbsp;&nbsp;</p>';
													$
															.each(
																	b.speakers,
																	function(q,
																			p) {
																		if (q == 4) {
																			n += '<p class="summary">...</P>';
																			return false
																		}
																		n += '<p class="summary">'
																				+ p.realname
																				+ " "
																				+ p.position
																				+ "</p>"
																	})
												}
												n += '<p class="title"><span class="light-grey">内容简介</span>&nbsp;&nbsp;</p>';
												n += '<p class="summary">'
														+ b.summary.substr(0,
																100) + "...";
												n += '<a href="'
														+ global.context
														+ "/event/" + b.id
														+ '">[活动详情]</a>';
												if (b.has_ppt == 1) {
													n += '<a href="'
															+ global.context
															+ "/event/"
															+ b.id
															+ '#res-download">[PPT下载]</a>'
												}
												n += "</p>";
												l.innerHTML = n;
												d.appendChild(g);
												d.appendChild(j);
												d.appendChild(l);
												m.appendChild(k);
												m.appendChild(d);
												$("#event-list-ul").append(m)
											});
							current_page++;
							ajax_lock = 0;
							$("#see-more").html("查看更多(10条)");
							if (a.code == 0) {
								$("#event-year-label").hide()
							}
						} else {
							ajax_lock = 0;
							$("#event-year-label").hide()
						}
					})
}
function show_contact_modal() {
	$("#contact_modal").modal("show");
	$("#contact_text").focus()
}
var init_text;
function submit_contact_info() {
	$("#contact_modal").modal("hide");
	var b = $("#contact_text").val();
	if (b.length < 70) {
		alert("请按照格式填写");
		return
	}
	var a = $("#contact_title").val();
	jQuery.ajax({
		type : "post",
		url : global.context + "/suggest/submit_suggestion",
		dataType : "xml",
		data : {
			text : b,
			title : a
		},
		success : function(c) {
			if (jQuery(c).find("ret").text() != 0) {
				alert("系统忙，请稍后重试")
			} else {
				alert("发送成功")
			}
			$("#contact_text").val(init_text)
		}
	})
}
$(document).ready(function() {
	init_text = $("#contact_text").val()
});